//
//  NewsShareCell.m
//  WanCaiC8
//
//  Created by tangang on 2018/4/22.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "NewsShareCell.h"
#import "AdvertisingView.h"
@interface NewsShareCell()
@property (nonatomic ,strong) AdvertisingView        *oneAdvertisingView;
@property (nonatomic ,strong) AdvertisingView        *twoAdvertisingView;
@end

@implementation NewsShareCell{
    QXLable     *labPrevious;
    QXLable     *labNext;
    OtherNewsModel *previousModel;
    OtherNewsModel *nextModel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor=[UIColor whiteColor];
        
        UIView *topLine=[[UIView alloc]init];
        topLine.backgroundColor=DEFAULTBGCOLOR;
        [self.contentView addSubview:topLine];
        [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self.contentView);
            make.height.mas_equalTo(@.7);
        }];
        
        QXLable *labTitle=[[QXLable alloc]initCenterTextWithText:@"分享文章"];
        labTitle.textColor=DEFAULTTEXTBLACKCOLOR;
        labTitle.font=[UIFont systemFontOfSize:15];
        [self.contentView addSubview:labTitle];
        [labTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contentView);
            make.top.equalTo(self.contentView).with.offset(10);
        }];
        
        UIButton *btnWechat=[[UIButton alloc]init];
        [btnWechat setImage:[UIImage imageNamed:@"share_wechat"] forState:UIControlStateNormal];
        [btnWechat setTitle:@"微信好友" forState:UIControlStateNormal];
        [btnWechat setTitleColor:DEFAULTTEXTBLACKCOLOR forState:UIControlStateNormal];
        [btnWechat addTarget:self action:@selector(onclickShare:) forControlEvents:UIControlEventTouchUpInside];
        btnWechat.tag=0;
        [btnWechat.titleLabel setFont:[UIFont systemFontOfSize:13]];
        [btnWechat verticalTopImageAndTitle:20 andImage:[UIImage imageNamed:@"share_wechat"]];
        [self.contentView addSubview:btnWechat];
        [btnWechat mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView);
            make.top.equalTo(labTitle.mas_bottom).with.offset(10);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH/3.0, 80));
        }];
        
        UIButton *btnFriend=[[UIButton alloc]init];
        [btnFriend setImage:[UIImage imageNamed:@"CircleFriends"] forState:UIControlStateNormal];
        [btnFriend setTitle:@"朋友圈" forState:UIControlStateNormal];
        [btnFriend setTitleColor:DEFAULTTEXTBLACKCOLOR forState:UIControlStateNormal];
        [btnFriend addTarget:self action:@selector(onclickShare:) forControlEvents:UIControlEventTouchUpInside];
        btnFriend.tag=1;
        [btnFriend.titleLabel setFont:[UIFont systemFontOfSize:13]];
        [btnFriend verticalTopImageAndTitle:20 andImage:[UIImage imageNamed:@"CircleFriends"]];
        [self.contentView addSubview:btnFriend];
        [btnFriend mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contentView);
            make.top.equalTo(labTitle.mas_bottom).with.offset(10);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH/3.0, 80));
        }];
        
        UIButton *btnQQ=[[UIButton alloc]init];
        [btnQQ setImage:[UIImage imageNamed:@"share_qq"] forState:UIControlStateNormal];
        [btnQQ setTitle:@"QQ好友" forState:UIControlStateNormal];
        [btnQQ setTitleColor:DEFAULTTEXTBLACKCOLOR forState:UIControlStateNormal];
        [btnQQ.titleLabel setFont:[UIFont systemFontOfSize:13]];
        [btnQQ verticalTopImageAndTitle:20 andImage:[UIImage imageNamed:@"share_qq"]];
        [btnQQ addTarget:self action:@selector(onclickShare:) forControlEvents:UIControlEventTouchUpInside];
        btnQQ.tag=2;
        [self.contentView addSubview:btnQQ];
        [btnQQ mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView);
            make.top.equalTo(labTitle.mas_bottom).with.offset(10);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH/3.0, 80));
        }];
        
        UIView  *line=[[UIView alloc]init];
        line.backgroundColor=DEFAULTBGCOLOR;
        [self.contentView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView);
            make.height.mas_equalTo(@.7);
            make.top.equalTo(btnWechat.mas_bottom).with.offset(10);
        }];
        
        [self.contentView addSubview:self.oneAdvertisingView];
        [self.oneAdvertisingView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.contentView).offset(10);
            make.right.equalTo(self.contentView).offset(-10);
            make.top.equalTo(line.mas_bottom);
            make.height.mas_equalTo(@0);
        }];
        
        
        labNext =[[QXLable alloc] initTitle];
        UITapGestureRecognizer *tap1=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onclickNext)];
        [labNext addGestureRecognizer:tap1];
        labNext.userInteractionEnabled=YES;
        [self.contentView addSubview:labNext];
        [labNext mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).with.offset(10);
            make.right.equalTo(self.contentView).with.offset(-10);
            make.top.equalTo(self.oneAdvertisingView.mas_bottom).with.offset(10);
        }];
        
        labPrevious =[[QXLable alloc] initTitle];
        labPrevious.userInteractionEnabled=YES;
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onclickPrevious)];
        [labPrevious addGestureRecognizer:tap];
        [self.contentView addSubview:labPrevious];
        [labPrevious mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).with.offset(10);
            make.right.equalTo(self.contentView).with.offset(-10);
            make.top.equalTo(labNext.mas_bottom).with.offset(10);
        }];
        
        
        
        UIView  *line1=[[UIView alloc]init];
        line1.backgroundColor=DEFAULTBGCOLOR;
        [self.contentView addSubview:line1];
        [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView);
            make.height.mas_equalTo(@.7);
            make.top.equalTo(labPrevious.mas_bottom).with.offset(20);
        }];
        
        [self.contentView addSubview:self.twoAdvertisingView];
        
        [self.twoAdvertisingView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(10);
            make.right.equalTo(self.contentView).offset(-10);
            make.top.equalTo(line1.mas_bottom);
            make.height.mas_equalTo(@0);
            make.bottom.equalTo(self.contentView).offset(-5);
        }];
        
    }
    return self;
}

- (void)setArr4:(NSMutableArray *)arr4{
    self.oneAdvertisingView.dataArr=arr4;
}

- (void)setArr5:(NSMutableArray *)arr5{
    self.twoAdvertisingView.dataArr=arr5;
}

- (void)setPrevious:(OtherNewsModel *)previous andNext:(OtherNewsModel *)next{
    previousModel=previous;
    nextModel=next;
    if (previous.Title.length>0) {
        labPrevious.text=[NSString stringWithFormat:@"上一篇:%@",previous.Title];;
    }
    if (next.Title.length>0) {
        labNext.text=[NSString stringWithFormat:@"下一篇:%@",next.Title];;
    }
    
}

- (void)onclickShare:(UIButton *)sender{
    
    
    [ShareHelper shareWithInfomation:sender.tag andTitle:self.contentModel];
}

- (void)onclickPrevious{
    if (self.otherBlock) {
        self.otherBlock(previousModel);
    }
}

- (void)onclickNext{
    if (self.otherBlock) {
        self.otherBlock(nextModel);
    }
}

- (AdvertisingView *)oneAdvertisingView{
    if (!_oneAdvertisingView) {
        WS(weakSelf);
        _oneAdvertisingView =[[AdvertisingView alloc]init];
        _oneAdvertisingView.noTimel=YES;
        self.oneAdvertisingView.changeHeight = ^(float height) {
            [weakSelf.oneAdvertisingView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(@(height));
            }];
        };
        
        
    }
    return _oneAdvertisingView;
}

- (AdvertisingView *)twoAdvertisingView{
    if (!_twoAdvertisingView) {
        WS(weakSelf);
        _twoAdvertisingView =[[AdvertisingView alloc]init];
        _twoAdvertisingView.noTimel=YES;
        self.twoAdvertisingView.changeHeight = ^(float height) {
            [weakSelf.twoAdvertisingView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(@(height));
            }];
        };
        
    }
    return _twoAdvertisingView;
}

@end
